home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000…tember: Reference Library / Dev.CD Sep 00 RL Disk 1.toast / mac / What's New / • What was new 08⁄00 / Sample Code / Interapplication Comm / MoreOSL / MoreQuickDraw / MoreQuickDraw.cp next >
Encoding:
Text File  |  2000-06-23  |  2.8 KB  |  128 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        MoreQuickDraw.cp
  3.  
  4.     Contains:    
  5.  
  6.     Written by:    Pete Gontier
  7.  
  8.     Copyright:    Copyright © 1998 Apple Computer, Inc. All Rights Reserved.
  9.  
  10.                 You may incorporate this Apple sample source code into your program(s) without
  11.                 restriction. This Apple sample source code has been provided "AS IS" and the
  12.                 responsibility for its operation is yours. You are not permitted to redistribute
  13.                 this Apple sample source code as "Apple sample source code" after having made
  14.                 changes. If you're going to re-distribute the source, we require that you make
  15.                 it clear in the source that the code was descended from Apple sample source
  16.                 code, but that you've made changes.
  17.  
  18.     Change History (most recent first):
  19.  
  20.          <5>     20/3/00    Quinn   Implement CreateNewPort and DisposePort for non-Carbon clients.
  21.          <4>      2/9/99    PCG     more TARGET_CARBON
  22.          <3>     1/22/99    PCG     TARGET_CARBON
  23.          <2>    11/11/98    PCG     fix header
  24.          <1>    11/10/98    PCG     first big re-org at behest of Quinn
  25.  
  26.     Old Change History (most recent first):
  27.  
  28.          <2>     8/28/98    PCG     add IsColorGrafPort
  29.          <1>     6/16/98    PCG     initial checkin
  30. */
  31.  
  32. #include "MoreQuickDraw.h"
  33.  
  34. #include <LowMem.h>
  35. #include <Gestalt.h>
  36.  
  37. static long gQuickDrawVersion;
  38.  
  39. pascal Boolean HaveColorQuickDraw (void)
  40. {
  41.     // the "features" selector is wrong; test the version instead
  42.     return gQuickDrawVersion > gestaltOriginalQD;
  43. }
  44.  
  45. pascal OSErr InitMoreQuickDraw (void)
  46. {
  47.     OSErr err = Gestalt (gestaltQuickdrawVersion,&gQuickDrawVersion);
  48.  
  49.     if (err == gestaltUndefSelectorErr)
  50.     {
  51.         gQuickDrawVersion = gestaltOriginalQD;
  52.         err = noErr;
  53.     }
  54.  
  55.     return err;
  56. }
  57.  
  58. pascal Boolean IsColorGrafPort (GrafPtr port)
  59. {
  60. #if TARGET_API_MAC_CARBON
  61. #    pragma unused (port)
  62.     return true;
  63. #else
  64.     // stolen from {CommonSystem}:Toolbox:ToolboxUtils:CommonHeaders:ColorUtils.h
  65.     return ((CGrafPtr) port)->portVersion < 0;
  66. #endif
  67. }
  68.  
  69. pascal OSErr ShowWatchCursor (void)
  70. {
  71.     OSErr err = noErr;
  72.  
  73.     CursHandle watchFob = GetCursor (watchCursor);
  74.  
  75.     if (!watchFob)
  76.         err = nilHandleErr;
  77.     else
  78.     {
  79.         Cursor preservedArrow;
  80.         GetQDGlobalsArrow (&preservedArrow);
  81.         SetQDGlobalsArrow (*watchFob);
  82.         InitCursor ( );
  83.         SetQDGlobalsArrow (&preservedArrow);
  84.     }
  85.  
  86.     return err;
  87. }
  88.  
  89. #if !TARGET_API_MAC_CARBON
  90.  
  91. pascal QDGlobalsPtr GetQDGlobalsPtr (void)
  92. {
  93.     return QDGlobalsPtr (* (Ptr*) LMGetCurrentA5 ( ) - 0xCA);
  94. }
  95.  
  96. #endif
  97.  
  98. pascal void SetArrowCursor (void)
  99. {
  100. #if TARGET_API_MAC_CARBON
  101.     Cursor arrow;
  102.     SetCursor (GetQDGlobalsArrow (&arrow));
  103. #else
  104.     SetCursor (&(qd.arrow));
  105. #endif
  106. }
  107.  
  108. #if !TARGET_API_MAC_CARBON
  109.  
  110.     extern pascal CGrafPtr CreateNewPort(void)
  111.     {
  112.         CGrafPtr result;
  113.         
  114.         result = (CGrafPtr) NewPtr(sizeof(CGrafPort));
  115.         if (result != nil) {
  116.             OpenCPort(result);
  117.         }
  118.         return result;
  119.     }
  120.     
  121.     extern pascal void DisposePort(CGrafPtr port)
  122.     {
  123.         DisposePtr( (Ptr) port );
  124.         MoreAssertQ(MemError() == noErr);
  125.     }
  126.  
  127. #endif
  128.